#include "mmu.h"

  # vectors.S sends all traps here.
.globl alltraps
alltraps:
  # Build trap frame.
  pushl %ds
  pushl %es
  pushl %fs
  pushl %gs
  pushal
  # 上面的命令依次push下面的寄存器
  # eax,ecx,edx,ebx,原esp(即执行pushal之前的esp),ebp,esi,edi
  
  # Set up data segments.
  # 为什么左移三位？见volume3 fig3-6 segment selector
  movw $(SEG_KDATA<<3), %ax
  movw %ax, %ds
  movw %ax, %es

  # Call trap(tf), where tf=%esp
  # 传参，调用trap
  pushl %esp
  call trap
  addl $4, %esp

  # Return falls through to trapret...
.globl trapret
trapret:
  # 取出之前push的寄存器值，在trap中可能会对寄存器进行操作
  popal
  popl %gs
  popl %fs
  popl %es
  popl %ds
  # 平衡栈操作
  addl $0x8, %esp  # trapno and errcode
  # 平衡之后
  iret
